layui.use(['layer','form','table','element'],function () {
    var layer = layui.layer
        ,form = layui.form
        ,table =layui.table
        ,element = layui.element;


    //初始化数据表格
    table.render({
        elem:"#data"
        ,height: 340
        ,url:"/admin/getUnCheckInfo"
        ,cellMinWidth: 80
        ,cols: [[
            {field:'id',width:60,title: 'ID', sort: true}
            ,{field:'userName', title: '用户名',width: 180}
            ,{field:'trueName', width: 180   , title: '真实姓名'}
            ,{field:'phone', width: 180   , title: '手机号'}
            ,{field:'idCard', width: 180   , title: '身份证'}
            ,{field:'',width:170,title: '操作',toolbar: '#barDemo'}
        ]]
        ,page:true
    });


    //监听工具条
    table.on('tool(dataTable)',function (obj) {
        var data = obj.data;
      if(obj.event == 'check'){

            layer.confirm('确定审核通过？', function(index){
                layer.msg('审核中...', { icon: 16, shade: [0.5, '#f5f5f5'], scrollbar: false, offset: '50%', time: 300000 });

                $.ajax({
                    type:"POST"
                    ,url:"/admin/driver/check"
                    ,data:{
                        id:data.id
                    }
                    ,success:function (result) {
                        layer.msg(result.message);
                        table.reload("data");
                    }
                    ,error:function () {
                        layer.msg("系统错误");
                    }

                });

            });

        }else if(obj.event == 'checkFail'){
          layer.prompt({title: '请输入审核失败原因', formType: 2}, function(text, index){

              layer.msg('审核中...', { icon: 16, shade: [0.5, '#f5f5f5'], scrollbar: false, offset: '50%', time: 300000 });

              $.ajax({
                  type:"POST"
                  ,url:"/admin/driver/checkFail"
                  ,data:{
                      id:data.id
                      ,reason:text
                  }
                  ,success:function (result) {
                      layer.msg(result.message);
                      table.reload("data");
                  }
                  ,error:function () {
                      layer.msg("系统错误");
                  }

              });
          });


          // layer.confirm('确定审核失败？', function(index){
          //     layer.msg('审核中...', { icon: 16, shade: [0.5, '#f5f5f5'], scrollbar: false, offset: '50%', time: 300000 });
          //
          //
          //
          // });
      }
    });


    $("#payBtn").bind("click",function () {
        alert("hello");
    })

    function rightMenu(){

        $(".layui-tab-title li",window.parent.document).on("contextmenu",function (e) {
            var rightmenu = $(".rightmenu",window.parent.document);
            rightmenu.find("li").attr('data-id',$(this).attr("lay-id"));
            l = e.clientX;
            t = e.clientY;
            rightmenu.css({ left:l, top:t}).show();
            return false;
        });
        //左键点击隐藏
        $("body,.layui-tab-title li",window.parent.document).click(function(){
            $(".rightmenu").hide();
        });

    }

    function iframeWH(){
        var H = $(window).height();
        $("iframe",window.parent.document).css("height",H+"px");
    }

    //搜索
    $("#search").on("click",function () {
        table.reload("data",{
            page:{
                curr:1
            }
            ,where:{
                userName:$("#userName").val(),
                trueName:$("#trueName").val()
            }
        })
    });;

    $("#add").on("click",function () {

        parent.layui.element.tabAdd('tabs',{
            title:"新增司机新增",
            content:"<iframe  src='/admin/driver/toAdd'  frameborder='0'  style='width:100%;height: 100%'></iframe>",
            id:"driver_add"
        });
        rightMenu();
        iframeWH();
        parent.layui.element.tabChange('tabs','driver_add');


    })


});
